import pygame
from pygame.sprite import Sprite

class Gun(Sprite):
    def __init__(self, screen):
        super(Gun, self).__init__()
        self.screen = screen
        self.image = pygame.image.load('assets/pixil-frame-0.png')
        self.rect = self.image.get_rect() #Пушка в виде прямоугольника
        self.screen_rect = screen.get_rect() #Облать экрана в виде rect
        self.rect.centerx = self.screen_rect.centerx
        self.center = float(self.rect.centerx)
        self.rect.bottom = self.screen_rect.bottom
        self.mright = False
        self.mleft = False
    def visualise(self):
        "Вывод пушки на экран"
        self.screen.blit(self.image,self.rect)

    def pos(self):
        "gun movement"

        if self.mright and self.rect.right < self.screen_rect.right:
            self.center += 0.8
        if self.mleft and self.rect.left > 0:
            self.center -= 0.8
        self.rect.centerx = self.center

    def gun_alive(self):
        self.center = self.screen_rect.centerx